#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <unistd.h>

static int pfd1[2], pfd2[2];

void TELL_WAIT() {
	if (pipe(pfd1) < 0 || pipe(pfd2) < 0) {
		printf("pipe error: %s\n", strerror(errno));
		return;
	}
}

void TELL_PARENT() {
	if (write(pfd2[1], "c", 1) != 1) {
		printf("write error: %s\n", strerror(errno));
		return;
	}
}

void TELL_CHILD() {
	if (write(pfd1[1], "p", 1) != 1) {
		printf("write error: %s\n", strerror(errno));
		return;
	}
}

void WAIT_PARENT() {
	char c;
	if (read(pfd1[0], &c ,1) != 1) {
		printf("read error\n");
		return;
	}

	if (c != 'p') {
		printf("WAIT_PARENT: incorrect data\n");
		return;
	}
}

void WAIT_CHILD() {
	char c;
	if (read(pfd2[0], &c ,1) != 1) {
		printf("read error\n");
		return;
	}

	if (c != 'c') {
		printf("WAIT_CHILD: incorrect data\n");
		return;
	}
}

int main() {
	printf("hello world\n");
	return 0;
}
